package com.cskaoyan.service.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cskaoyan.bean.bo.user.AdminUserListBO;
import com.cskaoyan.bean.po.user.AdminFootprintPO;
import com.cskaoyan.bean.po.user.AdminHistoryPO;
import com.cskaoyan.bean.vo.user.AdminFootprintVO;
import com.cskaoyan.bean.vo.user.AdminHistoryVO;
import com.cskaoyan.mapper.user.AdminHistoryMapper;
import com.cskaoyan.util.beanutils.BeanUtil;
import com.cskaoyan.util.common.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 冯子靖
 * @Description:
 * @Date: 2022/7/18 17:40
 */
@Data
@Service
public class AdminHistoryServiceImpl implements AdminHistoryService {
    private Integer limit;

    private Integer page;

    private Integer pages;

    private Integer total;

    private List<AdminHistoryPO> list;

    @Autowired
    AdminHistoryMapper adminHistoryMapper;
    @Override
    public AdminHistoryVO printAdminHistoryList(AdminUserListBO adminUserListBO) {
        page = adminUserListBO.getPage();
        limit = adminUserListBO.getLimit();

        Integer userId = adminUserListBO.getUserId();
        String keyword = adminUserListBO.getKeyword();

        PageHelper.startPage(page, limit);
        if (userId == null && StringUtils.isEmpty(keyword)) {
            list = adminHistoryMapper.selectList(null);

        } else {
            QueryWrapper<AdminHistoryPO> adminUserListPOQueryWrapper = new QueryWrapper<>();

            adminUserListPOQueryWrapper.eq(!(userId == null), "user_id", userId);
            adminUserListPOQueryWrapper.like(!StringUtils.isEmpty(keyword), "keyword", keyword);
            list = adminHistoryMapper.selectList(adminUserListPOQueryWrapper);
        }

        PageInfo<AdminHistoryPO> adminUserAddressPOPageInfo = new PageInfo<>(list);
        total = (int) adminUserAddressPOPageInfo.getTotal();
        pages = adminUserAddressPOPageInfo.getPages();
        AdminHistoryVO adminHistoryVO = new AdminHistoryVO();
        BeanUtil.copyBean(this, adminHistoryVO);
        return adminHistoryVO;
    }
}
